package entitys

import (
	"time"

	"github.com/jinzhu/gorm"
)

type SysApi struct {
	EntityInfo
	Id          int32  `gorm:"primary_key" json:"apiId"`
	ParentApiId int32  `json:"parentApiId"`
	CascadePath string `json:"cascadePath"`
	Type        int    `json:"type"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Method      string `json:"method"`
	Uri         string `json:"uri"`
	IsDel       int    `json:"isDel"`
}

type SysApiTree struct {
	SysApi
	Children []SysApiTree `json:"children"`
}

func (SysApi) TableName() string {
	return "sys_api"
}

func (sysApi *SysApi) BeforeCreate(scope *gorm.Scope) error {
	err := scope.SetColumn("CreaDtt", time.Now())
	err = scope.SetColumn("UptDtt", time.Now())
	return err
}

func (sysApi *SysApi) BeforeUpdate(scope *gorm.Scope) error {
	err := scope.SetColumn("UptDtt", time.Now())
	return err
}
